{include file="public/header" /}
<span class="layui-breadcrumb">
  <a href="{:url('Events/index')}?nav=events-eventslist">新闻事件</a>
  <a><cite>{if !empty($data_list['id']) }编辑{else/}添加{/if}新闻事件</cite></a>
</span>
<div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <div style="color:#FF5722">{if !empty($data_list['id']) }编辑{else/}添加{/if}新闻事件,返回页面后请刷新</div>
        <div class="layui-form">
         <form class="layui-form" action="" style='padding:10px;'>
          <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" value="{if !empty($data_list['title']) }{$data_list['title']}{/if}" autocomplete="off" placeholder="请输入标题" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">作者</label>
            <div class="layui-input-block">
                <!--<input type="text" name="author" value="{if !empty($data_list['author']) }{$data_list['author']}{/if}" autocomplete="off" placeholder="请输入作者" class="layui-input">-->
                <select name="author" id='author' lay-filter="aihao">
                    <option value=""></option>
                    {foreach $author as $key=>$vo }
                    {if !empty($data_list['author']) }
                    {if $data_list['author']==$vo['nickname']}
                    <option value="{$vo['nickname']}" selected="">{$vo['nickname']}</option>
                    {else /}
                    <option value="{$vo['nickname']}">{$vo['nickname']}</option>
                    {/if}
                    {else /}
                    <option value="{$vo['nickname']}">{$vo['nickname']}</option>
                    {/if}
                    {/foreach}

                </select>
            </div>
          </div>
          
           <div class="layui-form-item">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-block">
              <select name="class_zhi" id='class_zhi' lay-filter="aihao">
                <option value=""></option>
                {foreach $events as $key=>$vo }
                {if !empty($data_list['eventsclass']) }
                {if $data_list['eventsclass']['class_id']==$vo['class_id']}
                <option value="{$vo['class_id']}" selected="">{$vo['title']}</option>
                {else /}
                <option value="{$vo['class_id']}">{$vo['title']}</option>
                {/if}
                {else /}
                <option value="{$vo['class_id']}">{$vo['title']}</option>
                {/if}
                {/foreach}
                
              </select>
            </div>
          </div>
         <div class="layui-form-item">
             <label class="layui-form-label">是否用描点</label>
             <div class="layui-input-block">
                 <input type="radio" name="miaodian" value="1" title="是"  <?php if($data_list['miaodian']){ echo "checked";}?>>
                 <input type="radio" name="miaodian" value="0" title="否"  <?php if($data_list['miaodian']==0){ echo "checked";}?>>
             </div>
         </div>
          <div class="layui-form-item">
              <label class="layui-form-label">内容</label>
              <div class="layui-input-block">
                <textarea id="content" name="content" style="width:100%;height:300px;">{if !empty($data_list['content']) }{$data_list['content']}{/if}</textarea>
              </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">SEO标题</label>
            <div class="layui-input-block">
                <input type="text" name="seo_title" value="{if !empty($data_list['seo_title']) }{$data_list['seo_title']}{/if}" autocomplete="off" placeholder="请输入SEO标题" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">SEO关键字</label>
            <div class="layui-input-block">
                <input type="text" name="seo_key" value="{if !empty($data_list['seo_key']) }{$data_list['seo_key']}{/if}" autocomplete="off" placeholder="请输入SEO关键字" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">SEO描述</label>
            <div class="layui-input-block">
                <input type="text" name="seo_desc" value="{if !empty($data_list['seo_desc']) }{$data_list['seo_desc']}{/if}" autocomplete="off" placeholder="请输入SEO描述" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">url</label>
            <div class="layui-input-block">
                <input type="text" name="url" value="{if !empty($data_list['url']) }{$data_list['url']}{/if}" autocomplete="off" placeholder="请输入url" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">列表图</label>
            <div class="layui-input-block">
              <div class="layui-upload">
              <button type="button" class="layui-btn layui-btn-xs" id="upload_img">选择图片</button>
              <span style='color:#FF5722;font-size:12px'>视频及ie8不支持预览</span>
              <div class="layui-upload-list">
                <img class="layui-upload-img" style='width:200px' id="show_img" src="{if !empty($data_list['img']) }{$data_list['img']}{/if}">
                <p id="demoText"></p>
              </div>
            </div> 
            </div>
            <input type="text" name="newname" style="display:none" value="{if !empty($data_list['img']) }{$data_list['img']}{/if}">
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
              <button type="button" class="layui-btn layui-btn-sm" onclick="insert_edit({if !empty($data_list['id']) }{$data_list['id']}{else/}'tj'{/if})">确 定</button>
            </div>
          </div>
          
        </form>

        </div>
      </div>  
    </div>
</div>
{include file="/public/footer" /}

<script>
layui.use('upload', function(){
  var $ = layui.jquery
  ,upload = layui.upload;
  
  //普通图片上传
  var uploadInst = upload.render({
    elem: '#upload_img'
    ,accept: 'file'
    ,url: "{:url('index/Oos/upload_blog_img')}" //改成您自己的上传接口
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#show_img').attr('src', result); //图片链接（base64）
      });
    }
    ,done: function(res){
      //如果上传失败
      if(res.status == '0'){
        return layer.msg(res.msg);
      }else{ //上传成功
        $("input[name='newname']").val(res.newname);
        return layer.msg(res.msg);
      }
    }
    ,error: function(){
      //演示失败状态，并实现重传
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
  });
});  
</script>
<script charset="utf-8" src="/static/kindeditor/kindeditor-all.js"></script>
<script charset="utf-8" src="/static/kindeditor/lang/zh-CN.js"></script>
<script>
  KindEditor.ready(function(K) {
    window.editor=K.create('#content',{'items':['source', '|', 'undo', 'redo', '|','selectall', 'preview', 'print', 'code', 'cut', 'copy', 'paste','plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright','justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript','superscript', 'clearhtml', 'quickformat', '|','formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold','italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak','anchor', 'link', 'unlink','|', 'fullscreen'],'uploadJson':"{:url('index/Oos/upload_blog')}",afterCreate : function() { this.sync(); },afterBlur: function(){this.sync();}
    });

  })

  function insert_edit(id){
      layer.load();
      var title=$.trim($("input[name='title']").val());
      //var author=$.trim($("input[name='author']").val());
      var author=$.trim($("#author").val());
      var newname=$.trim($("input[name='newname']").val());
      var seo_title=$.trim($("input[name='seo_title']").val());
      var seo_key=$.trim($("input[name='seo_key']").val());
      var seo_desc=$.trim($("input[name='seo_desc']").val());
      var url1=$.trim($("input[name='url']").val());
      var content=$.trim($("textarea[name='content']").val());
      var class_zhi=$.trim($("#class_zhi").val());
      var miaodian=$("input[name='miaodian']:checked").val();
      
      if(title==''){
          layer.closeAll('loading');
          layer.msg('请填写标题');
          return false;
      }
      /*
      if(author==''){
          layer.closeAll('loading');
          layer.msg('请填写作者');
          return false;
      }
       */
      if(author==''){
          layer.closeAll('loading');
          layer.msg('请选择作者');
          return false;
      }
      if(class_zhi==''){
          layer.closeAll('loading');
          layer.msg('请选择分类');
          return false;
      }
      if(content==''){
          layer.closeAll('loading');
          layer.msg('请填写内容');
          return false;
      }
      if(seo_title==''){
          layer.closeAll('loading');
          layer.msg('请填写SEO标题');
          return false;
      }

      if(url1==''){
          layer.closeAll('loading');
          layer.msg('请填写url');
          return false;
      }

      if(newname==''){
          layer.closeAll('loading');
          layer.msg('请上传列表图');
          return false;
      }

      if(id=='tj'){
        var url="{:url('Events/do_change')}";
      }else{
        var url="{:url('Events/do_change')}"+"?id="+id;
      }
      $.post(url,{title:title,author:author,newname:newname,content:content,seo_title:seo_title,seo_key:seo_key,seo_desc:seo_desc,url1:url1,class_zhi:class_zhi,miaodian:miaodian},function(res){
        if(res.status=='0'){
            layer.closeAll('loading');
            layer.msg(res.msg);
        }
        if(res.status=='1'){
            layer.msg(
            res.msg,{time: 1500 },
            function(){
              layer.closeAll();
              location.href=location.href;
            });
        }
    }) 
  }
</script>


